#include"RBTree.h"

namespace MyMap{
    template<class K,class V>
    class Map{
        struct MapKeyOfT{
            const K& operator()(const pair<const K,V>& kv){
                return kv.first;
            }
        };

    public:

        typedef typename RBTree<K,pair<const K,V>,MapKeyOfT>::iterator iterator;
        typedef typename RBTree<K,pair<const K,V>,MapKeyOfT>::const_iterator const_iterator;

        iterator begin(){
            return _t.begin();
        }

        iterator end(){
            return _t.end();
        }

        const_iterator begin()const {
            return _t.begin();
        }

        const_iterator end()const{
            return _t.end();
        }

        //operator[],通过key值，返回value值，具备插入和修改
        V& operator[](const K& key){
            pair<iterator,bool> rit=insert(make_pair(key,V()));
            return rit.first->second;
        }

        pair<iterator,bool> insert(const pair<const K,V>& kv){
            return _t.insert(kv);
        }


    private:
        RBTree<K,pair<const K,V>,MapKeyOfT> _t;

    };
};